﻿@model ConferenceEventInformationMasterModel
@{
	ViewBag.Title = Resources.ConcurrentEventInformationMaster + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.EventName：<input id="searchEventName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a onclick="searchData()" class="easyui-linkbutton" iconcls="icon-search">@Resources.Search</a>
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceEventInformation, RoleType.浏览))
		{
			<a href="javascript:void(0);" id="export" class="easyui-linkbutton" iconcls="icon-export" onclick="exportData();" plain="true">@Resources.Export</a>
		}
	</div>
	<form id="frmExport" method="post" target="iframeDownload" action="@Url.Action(nameof(ConferenceEventInformationController.Export))">
		@Html.AntiForgeryToken()
		<input type="hidden" id="hdnIds" name="AllId" />
		<input type="hidden" id="conferenceIdForExport" name="ConferenceIdForExport" />
	</form>
	<iframe id="iframeDownload" style="width:0; height:0; visibility:hidden" tabindex="-1"></iframe>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceEventInformationMaster");
	common.setCurrentParentMenu("#menu_a1");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#conferenceIdForExport").val("@Model.ConferenceId");

		$("#searchEventName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});			

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceEventInformationController.GetData),
					nameof(ConferenceEventInformationController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
			method: "get",
			checkOnSelect: false,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100, 
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "chk", align: "center", checkbox: true },
				{ field: "eventName", title: "@Resources.EventName", align: "center", sortable: true, width: 150 },
				{ field: "fullName", title: "@Resources.FullName", align: "center", sortable: true, width: 200 },
				{ field: "affiliation", title: "@Resources.Affiliation", align: "center", sortable: true, width: 150 },
				{ field: "mobile", title: "@Resources.Telephone", align: "center", sortable: true, width: 150 },
				{ field: "mail", title: "@Resources.Mail", align: "center", sortable: true, width: 250 },
				{ field: "identityName", title: "@Resources.AttendenceIdentity", align: "center", sortable: true, width: 150 },
				{ field: "number", title: "@Resources.Number", align: "center", sortable: true, width: 150 },
				{ field: "totalFee", title: "@Resources.TotalFee", align: "center", sortable: false, width: 150 },
				{ field: "currency", title: "@Resources.Currency", align: "center", sortable: true, width: 100 },
				{
					field: "hasPaid", title: "@Resources.PaidStatus", align: "center", sortable: true, width: 150,
					formatter: function (value, rec) {
						if (value == true) {
							return "@Resources.HasPaid";
						} else if (value == false) {
							return "@Resources.HasNotPaid";
						} else {
							return "";
						}
					}
				},
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 250 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
				param.conferenceId = $("#hidConferenceId").val();
			},
			onLoadSuccess: function(data) {
				var exportIdList = $("#hdnIds").val();
				if (data.rows.length > 0) {
					var exportIdArray = exportIdList.split(',');
					for (var rowIndex = 0; rowIndex < data.rows.length; rowIndex++) {
						for (var index = 0; index < exportIdArray.length; index++) {
							if (data.rows[rowIndex].id == exportIdArray[index]) {
								$("input[type='checkbox']").eq(rowIndex + 1).prop("checked", true);
								break;
							}
						}
					}
				}
			},
			onCheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var strId = rowData.paymentInfoId.toString();
				if (exportIdList == "") {
					$("#hdnIds").val(strId);
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray.concat(strId);
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				var strId = rowData.paymentInfoId.toString();
				exportIdArray.remove(strId);
				$("#hdnIds").val(exportIdArray.join());
			},
			onCheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				if (exportIdList == "") {
					var newArray = new Array();
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].paymentInfoId.toString();
						newArray = newArray.concat(strId);
					}
					$("#hdnIds").val(newArray.join());
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray;
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].paymentInfoId.toString();
						if (newArray.indexOf(strId) < 0) {
							newArray = newArray.concat(strId);
						}
					}
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				for (var index = 0; index < rows.length; index++) {
					var strId = rows[index].paymentInfoId.toString();
					exportIdArray.remove(strId);
				}
				$("#hdnIds").val(exportIdArray.join());
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 110
			});
		});
	});

	function searchData() {
		$("#hdnIds").val("");
		$("#dataGrid").datagrid("load", {
			searchEventName: $("#searchEventName").textbox("getValue"),
		});
	}

	function exportData() {
		var exportIdList = $("#hdnIds").val();

		if (exportIdList == "") {
			$.messager.alert("@Resources.Export", "@Resources.MsgRecordMust", "warning");
			return;
		}
		$("#frmExport").submit();
	}
</script>
}